package com.bll.imple.userAction;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.bean.UserBean;
import com.bll.Action;
import com.dao.UserDao;

public class UserLoginAction implements Action{

	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		String lujing=request.getParameter("lujing");
		String lujing1=request.getParameter("lujing1");
		System.out.println("lujing:"+lujing);
		System.out.println("lujing1:"+lujing1);
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		HttpSession session=request.getSession();
		session.setAttribute("username", username);
		session.setAttribute("password", password);
		System.out.println("username:"+username);
		System.out.println("password:"+password);
		UserDao dao=new UserDao();
		UserBean bean=null;
		if(username.contains("@")==true){
			bean=dao.loginE(username, password);
		}else{
			bean=dao.login(username, password);
			session.setAttribute("userId", bean.getId());
		}
		if(bean!=null){
			return lujing+"?lujing="+lujing1;
		}else{
			return "login.html";
		}
	
	}

}
